package com.supermap.application.dao;


import com.supermap.application.entity.TIndexSysTypeCol;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * 目标体系-详细指标
 */
@Repository
public interface TargetManageIndexSysTypeColDao extends JpaRepository<TIndexSysTypeCol,String> {

    //根据指标类型id查询
    @Query("select t from TIndexSysTypeCol t where t.type_id = :type_id and t.name is not null ")
    List<TIndexSysTypeCol> findAllByType_id(@Param("type_id") String type_id);

    //根据pid查询 是否有子节点
    @Query("select t from TIndexSysTypeCol t where t.pid = :pid")
    List<TIndexSysTypeCol> findAllByPid(@Param("pid") String pid);

    //根据指标名称查询
    @Query("select t from TIndexSysTypeCol t where t.name = :name")
    TIndexSysTypeCol findByName(@Param("name") String name);

    //根据code查询type_id
    @Query("select t.type_id from TIndexSysTypeCol t where t.code = :code")
    List<TIndexSysTypeCol> findType_IdByCode(@Param("code") String code);

    //根据code, index_sys_id, type_id确定指标是否已添加
    @Query("select t from TIndexSysTypeCol t where t.code = :code and t.index_sys_id = :index_sys_id and t.type_id =:type_id")
    TIndexSysTypeCol findByCodeAndIndex_sys_idAndType_id(@Param("code") String code, @Param("index_sys_id") String index_sys_id, @Param("type_id") String type_id);

    //根据index_sys_id查询目标体系下所有指标
    @Query("select t from TIndexSysTypeCol t where t.index_sys_id = :index_sys_id")
    List<TIndexSysTypeCol> findAllByIndex_sys_id(@Param("index_sys_id") String index_sys_id);
}
